package com.flbill.common.utils;

import com.flbill.common.exception.UserNotLoginException;

public class BaseContext {

    public static ThreadLocal<Long> threadLocal = new ThreadLocal<>();

    public static void setCurrentId(Long id) {
        threadLocal.set(id);
    }

    public static Integer getCurrentId() {
        Long id = threadLocal.get();
        if (id == null) {
            throw new UserNotLoginException("用户未登录");
        }
        return Math.toIntExact(threadLocal.get());
    }

    public static void removeCurrentId() {
        threadLocal.remove();
    }

}